<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
 <form role="form" method="POST" name="statisticprovince">  
<div class="row">
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-body">
                <div class="row">
                    <div class="col-lg-12">
                        <div class="row">
                            <div class="col-lg-2">
                                Từ ngày:
                            </div>
                            <div class="col-lg-3">
                                <input class="form-control" type="datetime" name="from_date" id="from_date" value="<?php echo $this->fromdate; ?>">        
                            </div>
                            <div class="col-lg-2">
                                Đến:
                            </div>
                            <div class="col-lg-3">
                                <input class="form-control" type="datetime" name="to_date" id="to_date" value="<?php echo $this->todate; ?>">        
                            </div>
                             <div class="col-lg-2">
                            <button class="btn btn-primary" type="submit" id="submit">Thống kê</button>   
                        </div>
                        </div>
                        
                    </div>
                    <div class="col-lg-12">
                                <div class="row">
                                <div class="col-lg-2">
                                    Sản phẩm
                                </div>
                                <div class="col-lg-3" id="agent">
                                    <?php echo $this->productHTML ?>      
                                </div>
                                <div class="col-lg-2">
                                    Nhóm sản phẩm
                                </div>
                                <div class="col-lg-3">
                                    <?php echo $this->groupproductHTML ?> 
                                </div>
                                <div class="col-lg-2">
                                    
                                </div>
                            </div>
                         </div>
                </div>
                
            </div>
        </div>
    </div>
</div>
 </form>
<script>
    $(document).ready(function(){
    $('.form-control').datepicker({showAnim: 'drop', dateFormat: 'dd-mm-yy', showWeek: false, showButtonPanel: false});
    });
    $('#product_id').multiselect({
         includeSelectAllOption:true,
            enableFiltering: true,
            maxHeight: '300',
            buttonText: function(options) 
            {
                var retStr = "";
                if (options.length === 0) {
                   retStr = "None selected";
                } else if(options.length <=2){
                   var textArray = [];
                   $.each(options,function(key,value){
                       textArray.push($.trim($(value).html()));
                   });
                   retStr = "<div class='pull-left restricted'>"+textArray.join(",")+"</div>";
                } else {
                   retStr = options.length+" selected";
                }
                return retStr+" <b class='caret'></b>";
            }  
        });
    $('#groupproduct_id').multiselect({
         includeSelectAllOption:true,
            enableFiltering: true,
            maxHeight: '300',
            buttonText: function(options) 
            {
                var retStr = "";
                if (options.length === 0) {
                   retStr = "None selected";
                } else if(options.length <=2){
                   var textArray = [];
                   $.each(options,function(key,value){
                       textArray.push($.trim($(value).html()));
                   });
                   retStr = "<div class='pull-left restricted'>"+textArray.join(",")+"</div>";
                } else {
                   retStr = options.length+" selected";
                }
                return retStr+" <b class='caret'></b>";
            }  
        });
</script>
<div class="row">  
    <div class="col-lg-12">
        <div class="panel panel-default">
            <div class="panel-body">
                <div class="row">
                    <div class="panel-body">
                        <div class="table-reponsive">
                            <div id="container">
                            </div>
                        </div>
                    </div>  
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
$(document).ready(function () {
    var chart;
    var series=[];
    var options={
        chart: {
            renderTo:'container',
            type: 'column',
        },
        title: {
            text: 'Thông kế số lượng sản phẩm Đại lý bán'
        },
        
        xAxis: {
            type: 'category',
            labels: {
                rotation: -45,
                style: {
                    fontSize: '13px',
                    fontFamily: 'Verdana, sans-serif'
                }
            }
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Số lượng bán được (Tấn)'
            }
        },
        legend: {
            enabled: false
        },
        tooltip: {
            pointFormat: 'Số lượng bán được: <b>{point.y:.1f} Tấn</b>'
        },
        series: []
    };

    $.getJSON("<?php echo $this->baseUrl() ?>/admin/statistic/statisticproductbuy/", 
            {
                fromdate: "<?php echo $this->fromdate; ?>",
                todate: "<?php echo $this->todate; ?>",
                product_id: "<?php echo $this->product_id; ?>",
                groupproduct_id: "<?php echo $this->groupproduct_id; ?>"
            },function (items) {
            series.push({
                    data:items,
                    dataLabels: {
                        enabled: true,
                        rotation: 0,
                        color: '#606060',
                        align: 'right',
                        format: '{point.y:.1f}', // one decimal
                        y: 0, // 10 pixels down from the top
                        style: {
                            fontSize: '13px',
                            fontFamily: 'Verdana, sans-serif'
                        }
                    }
            });            
            options.series = series;
            chart = new Highcharts.Chart(options);
        });
        chart.render();
});
</script>
<script type="text/javascript">
$('#submit-tmp').click(function () {
    var chart;
    var series=[];
    var options={
        chart: {
            renderTo:'container',
            type: 'column',
        },
        title: {
            text: 'Thông kế số lượng sản phẩm Đại lý bán'
        },
        
        xAxis: {
            type: 'category',
            labels: {
                enabled: true,
                rotation: -45,
                style: {
                    fontSize: '13px',
                    fontFamily: 'Verdana, sans-serif'
                }
            }
        },
        yAxis: {
            min: 0,
            title: {
                text: 'Số lượng bán được (Tấn)'
            }
        },
        legend: {
            enabled: false
        },
        tooltip: {
            pointFormat: 'Số lượng bán được: <b>{point.y:.1f} Tấn</b>'
        },       
        series: []
    };

    $.getJSON("<?php echo $this->baseUrl() ?>/admin/statistic/statisticproductbuy/", 
            {
                fromdate: $('#from_date').val(),
                todate:$('#to_date').val(),
                product_id: "<?php echo $this->product_id; ?>",
                groupproduct_id: "<?php echo $this->groupproduct_id; ?>"
            },function (items) {
            series.push({
                    data:items
            });
            
            //options.series = series;
            chart = new Highcharts.Chart(options);
        });
        chart.render();
});
</script>
